﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_SMS_GetNewMsg]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_SMS_GetNewMsg];
GO
CREATE PROCEDURE [dbo].[sproc_SMS_GetNewMsg]
    @Username nvarchar(255)
    
/*

===================================================
功能:    1.更新activetime         
    2.判断sessionid            
    3.删除十分钟内未活动人
    4.拿到最新在线人数得到在线人数
参数:
    @Username  用户名
        
返回值:
    
===================================================

*/
AS

SET NOCOUNT ON

--判断是否有未读新的短消息
SELECT top 1 *     
            FROM 
                UDS_SMS_Msg m,
                UDS_SMS_Receiver r 
            WHERE    
                r.Receiver = @Username 
                and m.ID=r.MsgID 
                and m.type = 1
                and r.IsRead=0 
            ORDER BY
                sendtime    
SET NOCOUNT OFF